package com.tailyou.hms.firstapp.act;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.tailyou.hms.firstapp.R;

import java.util.ArrayList;

public class ArrayAdapterActivity extends AppCompatActivity {

    private ArrayList<String> listData;
    private ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_array_adapter);
        ListView listView = findViewById(R.id.list);
        //准备要显示的数据
        getMyList();
        //新建ArrayAdapter
        adapter = new ArrayAdapter<String>(ArrayAdapterActivity.this, android.R.layout.simple_list_item_1, listData);
        //给ListView设置Adapter
        listView.setAdapter(adapter);
    }

    private void getMyList() {
        listData = new ArrayList<String>();
        for (int i = 1; i < 20; i++) {
            listData.add("数据" + i);
        }
    }

}